package com.mw.job.zookeeper;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by mengdexuan on 2017/9/30 13:46.
 */
public class ZkWatch implements Watcher {

	private static Logger log = LoggerFactory.getLogger(ZkWatch.class);

	@Override
	public void process(WatchedEvent event) {
		if(event == null){
			return;
		}
		Event.KeeperState keeperState = event.getState();
		Event.EventType eventType  = event.getType();
		if ( Event.KeeperState.SyncConnected == keeperState) {
			if ( Event.EventType.None == eventType) {
				log.info("成功连接上ZK服务器！");
			}
		}else if ( Event.KeeperState.Disconnected == keeperState ) {
			log.info("与ZK服务器断开连接！");
		} else if ( Event.KeeperState.AuthFailed == keeperState ) {
			log.info("权限检查失败！");
		} else if ( Event.KeeperState.Expired == keeperState ) {
			log.info("会话失效！");
		}

	}
}
